/*
 SGGameProgressViewController.m
 Date Created: April 4, 2010
 
 Author: Frank Lau <flaua@sfu.ca>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version. 
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import "SGGameProgressViewController.h"


@implementation SGGameProgressViewController
@synthesize graphView;

- (SGGameProgressViewController*)initWithXValues:(NSMutableArray*)xValues initWithYValues:(NSMutableArray*)yValues{
	self=[super init];
	
  if(self) {
	xValuesForProgressChart = xValues;
	yValuesForProgressChart = yValues;
  }
	NSLog(@"gameprogressconstructor");
	return self;
}
      

- (void)viewDidLoad {
	[[self navigationController] setNavigationBarHidden:NO animated:YES];

	CGRect graphRect = CGRectMake(self.view.frame.origin.x + 15, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-50);
  self.graphView = [[S7GraphView alloc] initWithFrame:graphRect];
	[self.view addSubview:self.graphView];
	self.graphView.dataSource = self;
	
  //format the x axis values to be integers
	NSNumberFormatter *integerFormat = [[NSNumberFormatter alloc] init];
	[integerFormat setNumberStyle:NSNumberFormatterDecimalStyle];
	[integerFormat setMinimumFractionDigits:0];
	[integerFormat setMaximumFractionDigits:0];
    
  //format the y axis values to be decimal numbers
	NSNumberFormatter *percentFormat = [[NSNumberFormatter alloc] init];
  [percentFormat setMinimumFractionDigits:2];
	[percentFormat setMaximumFractionDigits:2];	
	[percentFormat setNumberStyle:NSNumberFormatterDecimalStyle];
	
	self.graphView.xValuesFormatter = integerFormat;
	self.graphView.yValuesFormatter = percentFormat;
		
	[integerFormat release];        
	[percentFormat release];
	
	self.graphView.backgroundColor = [UIColor whiteColor];
	
	self.graphView.drawAxisX = YES;
	self.graphView.drawAxisY = YES;
	self.graphView.drawGridX = YES;
	self.graphView.drawGridY = YES;
	
	self.graphView.xValuesColor = [UIColor blackColor];
	self.graphView.yValuesColor = [UIColor blackColor];
	
	self.graphView.gridXColor = [UIColor blackColor];
	self.graphView.gridYColor = [UIColor blackColor];
	
  //title for the progress chart
	self.graphView.drawInfo = YES;
	self.graphView.info = @"Sorting Accuracy verse Level Number";
	self.graphView.infoColor = [UIColor blackColor];
  
  //print label for the x axis
  UILabel *levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 30, self.view.frame.size.height-55, 90, 15)];
  levelLabel.text = @"Level Number";
  levelLabel.backgroundColor = [UIColor whiteColor];
  levelLabel.font = [UIFont systemFontOfSize:14];
  [self.view addSubview:levelLabel];
  [levelLabel release];
  
  //print label for the y axis and rotate label by 90 degrees to make vertical 
  UILabel *sortingAccuracyLabel = [[UILabel alloc] initWithFrame:CGRectMake(-55, self.view.frame.size.height/2-20, 150, 15)];
  sortingAccuracyLabel.text = @"Sorting Accuracy(%)";
  sortingAccuracyLabel.backgroundColor = [UIColor whiteColor];
  sortingAccuracyLabel.transform = CGAffineTransformMakeRotation( M_PI/2 );
  sortingAccuracyLabel.font = [UIFont systemFontOfSize:14];
  [self.view addSubview:sortingAccuracyLabel];
  [sortingAccuracyLabel release];

}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}


- (void) viewWillDisappear:(BOOL)animated{	
	[self navigationController].navigationBarHidden = YES;
}

- (void)dealloc {
  [super dealloc];
}


#pragma mark protocol S7GraphViewDataSource

- (NSUInteger)graphViewNumberOfPlots:(S7GraphView *)graphView {
	return 1; // Only going to have a single plot
}

- (NSArray *)graphViewXValues:(S7GraphView *)graphView {
	return xValuesForProgressChart; 
	
 }

- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex {
	return	yValuesForProgressChart; 
}



@end
